<template>
 <view>
  <view class="im-chat-main"> sdfsdf </view>
  <button @click="sendFn()">发送</button>
 </view>
</template>

<script setup>
import { reactive, getCurrentInstance, onMounted } from "vue";

import SDK from "@yxim/nim-web-sdk";
import { onLoad } from "@dcloudio/uni-app";
// import {useAccountStore} from '@/store/index.js'

var nim = null;
const nimFn = (o) => {
  nim = SDK.NIM.getInstance({
    debug: true, // 是否开启日志，将其打印到console。集成开发阶段建议打开。
    appKey: "c3a4ed2a80700c5133e5d8f82cc91073",
    account: o.iphone, //用于登录IM
    token: o.token, //用于登录IM
    db: true, //若不要开启数据库请设置false。SDK 默认为true。
    // privateConf: {}, // 私有化部署方案所需的配置
    // onconnect: onConnect,
    //消息收发的监听事件
    onmsg: onMsg,
  });
};

onLoad((option) => {
  nimFn(option);
});

const sendFn = () => {
  // let store = useAccountStore()
  // store.login(5)
  nim.sendText({
    scene: "p2p",
    to: "15102722132",
    text: "优秀11111111111111111111",
    done: sendMsgDone,
  });
};

function sendMsgDone(error, msg) {
  console.log(error);
  console.log(msg);
  console.log(
    "发送" +
      msg.scene +
      " " +
      msg.type +
      "消息" +
      (!error ? "成功" : "失败") +
      ", id=" +
      msg.idClient
  );
}

function onMsg(msg) {
  console.log("收到消息", msg.scene, msg.type, msg);
  // pushMsg(msg);
  switch (msg.type) {
    case "custom":
      // onCustomMsg(msg);
      break;
    case "notification":
      // onTeamNotificationMsg(msg);
      break;
    // 其它case
    default:
      break;
  }
}
</script>

<style lang="scss" scoped>
</style>
